<template>
  <el-container class="box">
    <!-- 头部区域 -->
    <el-header>
      <!-- logo -->
      <div class="logo">
        <img src="../assets/logo.png" alt="" />
        <span class="logo-font">后台管理系统</span>
      </div>
      <!-- 退出 -->
      <el-button type="info" round @click="loginOut">退出</el-button>
    </el-header>
    <!-- 主体区域 -->
    <el-container>
      <!-- 左侧导航区域 -->
      <el-aside  :width="iscollapse ? '60px' : '200px'">
         <!-- 折叠展开按钮 -->
        <div class="toggle-button" @click="toggleCollapse()">|||</div>
        <!-- 导航列表 -->
        <el-menu
          class="el-menu-vertical-demo"
          background-color="rgb(50, 55, 67)"
          text-color="#fff"
          active-text-color="#409EFF"
          unique-opened
          :collapse="iscollapse"
          :collapse-transition="false"
          router
        >
          <!-- 一级菜单区域 -->
          <el-submenu
            v-for="item in menuList"
            :key="item.id"
            :index="item.id + ''"
          >
            <!-- 一级菜单模板 -->
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级菜单区域 -->
            <el-menu-item 
            v-for="subitem in item.children" 
            :key="subitem.id"
            :index="'/' + subitem.path"
            >
              <!-- 二级菜单模板 -->
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ subitem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容区域 -->
      <el-main>
        <!-- 路由占位 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "home",
  data() {
    return {
      menuList: [
        {
          authName: "用户管理",
          id: 125,
          path: "users",
          children: [{
            id: 110,
            authName: '用户列表',
            path: 'users'
          }]
          },
        {
          authName: "权限管理",
          id: 103,
          path: "powers",
          children: [
            {
              id: 111,
              authName: '角色管理',
              path: "roles"
            },
            {
              id: 112,
              authName: '权限管理',
              path: "powers"
            }
          ]
        },
        {
          authName: "商品管理",
          id: 101,
          path: "goods",
          children: [
            {
              id: 113,
              authName: '商品添加',
              path: "addShops"
            },
            {
              id: 114,
              authName: '商品删除',
              path: "dels"
            }
          ]
        },
        {
          authName: "订单管理",
          id: 102,
          path: "orders",
          children: [
            {
              id: 115,
              authName: '订单核查',
              path: "checks"
            }
          ]
        },
        {
          authName: "数据统计",
          id: 145,
          path: "reports",
          children: [
            {
              id: 116,
              authName: '订单统计',
              path: "reports"
            }
          ]
        }
      ],
      iscollapse: false
    }
  },
  // 进入首页时执行，请求导航数据
  // created(){
  //   this.getMenuList()
  // },
  methods: {
    // 退出事件
    loginOut() {
      window.sessionStorage.clear("token");
      this.$router.push("/login");
    },
    // 进入首页时执行，发送get请求，请求导航列表数据
    // async getMenuList(){
    //   let {data: res} = await this.$http.get('menu');
    //   this.menuList = res.data
    //   console.log(res);
    // }
    // 导航列表折叠展开事件
    toggleCollapse() {
      this.iscollapse = ! this.iscollapse
    }
  }
}
</script>

<style lang="less" scoped>
.box {
  height: 100%;
  background-color: #000;
}
// 头部区域
.el-header {
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  line-height: 60px;
  font-size: 30px;
  padding: 10px;
  color: #fff;
  // background-color: #000;

  .logo {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .logo > img {
    width: 40px;
    height: 40px;
    margin-right: 10px;
  }

  .el-button {
    height: 30px;
    line-height: 5px;
  }
}
.el-container {
  height: 100%;
}

.el-submenu {
  width: 200px  ;
}

.toggle-button {
  background-color: #454f60;
  font-size: 10px;
  line-height: 24px;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
  color: #fff;
}

.el-main {
  background-color: rgb(230, 234, 236);
}
</style>